home *** CD-ROM | disk | FTP | other *** search
- ;;; -*- Package: VM; Log: C.Log -*-
- ;;;
- ;;; **********************************************************************
- ;;; This code was written as part of the CMU Common Lisp project at
- ;;; Carnegie Mellon University, and has been placed in the public domain.
- ;;; If you want to use this code or any part of CMU Common Lisp, please contact
- ;;; Scott Fahlman or slisp-group@cs.cmu.edu.
- ;;;
- (ext:file-comment
- "$Header: utils.lisp,v 1.3 92/03/12 15:25:02 wlott Locked $")
- ;;;
- ;;; **********************************************************************
- ;;;
- ;;; $Header: utils.lisp,v 1.3 92/03/12 15:25:02 wlott Locked $
- ;;;
- ;;; Utility functions needed by the back end to generate code.
- ;;;
- ;;; Written by William Lott.
- ;;;
-
- (in-package "VM")
-
- (export '(fixnum static-symbol-p static-symbol-offset offset-static-symbol
- static-function-offset))
-
-
-
- ;;;; Handy routine for making fixnums:
-
- (defun fixnum (num)
- "Make a fixnum out of NUM. (i.e. shift by two bits if it will fit.)"
- (if (<= #x-20000000 num #x1fffffff)
- (ash num 2)
- (error "~D is too big for a fixnum." num)))
-
-
-
- ;;;; Routines for dealing with static symbols.
-
- (defun static-symbol-p (symbol)
- (member symbol static-symbols))
-
- (defun static-symbol-offset (symbol)
- "Returns the byte offset of the static symbol Symbol."
- (let ((posn (position symbol static-symbols)))
- (unless posn (error "~S is not a static symbol." symbol))
- (+ (* posn (pad-data-block symbol-size))
- (pad-data-block (1- symbol-size))
- other-pointer-type
- (- list-pointer-type))))
-
- (defun offset-static-symbol (offset)
- "Given a byte offset, Offset, returns the appropriate static symbol."
- (multiple-value-bind
- (n rem)
- (truncate (+ offset list-pointer-type (- other-pointer-type)
- (- (pad-data-block (1- symbol-size))))
- (pad-data-block symbol-size))
- (unless (and (zerop rem) (<= 0 n (1- (length static-symbols))))
- (error "Byte offset, ~D, is not correct." offset))
- (elt static-symbols n)))
-
- (defun static-function-offset (name)
- "Return the (byte) offset from NIL to the start of the fdefn object
- for the static function NAME."
- (let ((static-syms (length static-symbols))
- (static-function-index (position name static-functions)))
- (unless static-function-index
- (error "~S isn't a static function." name))
- (+ (* static-syms (pad-data-block symbol-size))
- (pad-data-block (1- symbol-size))
- (- list-pointer-type)
- (* static-function-index (pad-data-block fdefn-size))
- (* fdefn-raw-addr-slot word-bytes))))
-